package com.woniuxy.config;


import com.woniuxy.controller.WebSocketService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import javax.annotation.Resource;

@Configuration
@EnableWebSocket
@Slf4j
public class WebSocketConfig implements WebSocketConfigurer {
    // 注入ServerEndpointExporter，自动注册使用@ServerEndpoint注解的Bean
    @Resource
    private WebSocketService webSocketService;
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 这里不需要注册，因为使用了@ServerEndpoint
    }

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        log.info("初始化WebSocket");
        return new ServerEndpointExporter();
    }
}
